﻿using System;
using System.Globalization;
using System.Windows.Forms;

namespace FlaskHelper
{
    public partial class SettingsForm : Form
    {
        public SettingsForm()
        {
            InitializeComponent();
        }

        #region Load/Close

        private void SettingsFormLoad(object sender, EventArgs e)
        {

            #region Flasks Data

            // life/mana flasks
            txt_lifeflasktr.Text = FlaskHelperSettings.Instance.LifeFlaskThreshold.ToString(CultureInfo.InvariantCulture);
            txt_manaflasktr.Text = FlaskHelperSettings.Instance.ManaFlaskThreshold.ToString(CultureInfo.InvariantCulture);

            // special flasks
            cb_EnableGranite.Checked = FlaskHelperSettings.Instance.UseGraniteFlask;
            txt_graniteFlaskTr.Text = FlaskHelperSettings.Instance.GraniteFlaskThreshold.ToString(CultureInfo.InvariantCulture);
            cb_EnableJade.Checked = FlaskHelperSettings.Instance.UseJadeFlask;
            txt_jadeflasktr.Text = FlaskHelperSettings.Instance.JadeFlaskThreshold.ToString(CultureInfo.InvariantCulture);
            cb_EnableRuby.Checked = FlaskHelperSettings.Instance.UseRubyFlask;
            txt_rubyflasktr.Text = FlaskHelperSettings.Instance.RubyFlaskThreshold.ToString(CultureInfo.InvariantCulture);
            cb_EnableDiamond.Checked = FlaskHelperSettings.Instance.UseDiamondFlask;
            txt_diamondflasktr.Text = FlaskHelperSettings.Instance.DiamondFlaskThreshold.ToString(CultureInfo.InvariantCulture);
            cb_EnableBleeding.Checked = FlaskHelperSettings.Instance.UseBleedingFlask;
            txt_bleedingflasktr.Text = FlaskHelperSettings.Instance.BleedingFlaskThreshold.ToString(CultureInfo.InvariantCulture);
            cb_EnableShock.Checked = FlaskHelperSettings.Instance.UseShockFlask;
            txt_shockflasktr.Text = FlaskHelperSettings.Instance.ShockFlaskThreshold.ToString(CultureInfo.InvariantCulture);
            cb_EnableBurning.Checked = FlaskHelperSettings.Instance.UseBurningFlask;
            txt_burningflasktr.Text = FlaskHelperSettings.Instance.BurningFlaskThreshold.ToString(CultureInfo.InvariantCulture);
            cb_EnableFrozen.Checked = FlaskHelperSettings.Instance.UseFrozenFlask;
            txt_frozenflasktr.Text = FlaskHelperSettings.Instance.FrozenFlaskThreshold.ToString(CultureInfo.InvariantCulture);
            cb_EnableDivination.Checked = FlaskHelperSettings.Instance.UseDivinationFlask;
            txt_divinationflasktr.Text = FlaskHelperSettings.Instance.DivinationFlaskThreshold.ToString(CultureInfo.InvariantCulture);
            cb_UseEnergypercentThresholds.Checked = FlaskHelperSettings.Instance.UseEnergyShieldThresholds;

            #endregion
        }

        private void SettingsFormClosing(object sender, EventArgs e)
        {
            #region Flasks Data

            // life/mana flasks
            FlaskHelperSettings.Instance.LifeFlaskThreshold = Convert.ToInt32(txt_lifeflasktr.Text);
            FlaskHelperSettings.Instance.ManaFlaskThreshold = Convert.ToInt32(txt_manaflasktr.Text);

            // special flasks
            FlaskHelperSettings.Instance.UseGraniteFlask = cb_EnableGranite.Checked;
            FlaskHelperSettings.Instance.GraniteFlaskThreshold = Convert.ToInt32(txt_graniteFlaskTr.Text);
            FlaskHelperSettings.Instance.UseJadeFlask = cb_EnableJade.Checked;
            FlaskHelperSettings.Instance.JadeFlaskThreshold = Convert.ToInt32(txt_jadeflasktr.Text);
            FlaskHelperSettings.Instance.UseRubyFlask = cb_EnableRuby.Checked;
            FlaskHelperSettings.Instance.RubyFlaskThreshold = Convert.ToInt32(txt_rubyflasktr.Text);
            FlaskHelperSettings.Instance.UseDiamondFlask = cb_EnableDiamond.Checked;
            FlaskHelperSettings.Instance.DiamondFlaskThreshold = Convert.ToInt32(txt_diamondflasktr.Text);
            FlaskHelperSettings.Instance.UseBleedingFlask = cb_EnableBleeding.Checked;
            FlaskHelperSettings.Instance.BleedingFlaskThreshold = Convert.ToInt32(txt_bleedingflasktr.Text);
            FlaskHelperSettings.Instance.UseShockFlask = cb_EnableShock.Checked;
            FlaskHelperSettings.Instance.ShockFlaskThreshold = Convert.ToInt32(txt_shockflasktr.Text);
            FlaskHelperSettings.Instance.UseBurningFlask = cb_EnableBurning.Checked;
            FlaskHelperSettings.Instance.BurningFlaskThreshold = Convert.ToInt32(txt_burningflasktr.Text);
            FlaskHelperSettings.Instance.UseFrozenFlask = cb_EnableFrozen.Checked;
            FlaskHelperSettings.Instance.FrozenFlaskThreshold = Convert.ToInt32(txt_frozenflasktr.Text);
            FlaskHelperSettings.Instance.UseDivinationFlask = cb_EnableDivination.Checked;
            FlaskHelperSettings.Instance.DivinationFlaskThreshold = Convert.ToInt32(txt_divinationflasktr.Text);
            FlaskHelperSettings.Instance.UseEnergyShieldThresholds = cb_UseEnergypercentThresholds.Checked;

            #endregion

            // Save Data
            FlaskHelperSettings.Instance.Save();
        }

        #endregion

        #region CheckBoxes

        private void CbEnableGraniteCheckedChanged(object sender, EventArgs e)
        {
            FlaskHelperSettings.Instance.UseGraniteFlask = cb_EnableGranite.Checked;
        }

        private void CbEnableJadeCheckedChanged(object sender, EventArgs e)
        {
            FlaskHelperSettings.Instance.UseJadeFlask = cb_EnableJade.Checked;
        }

        private void CbEnableRubyCheckedChanged(object sender, EventArgs e)
        {
            FlaskHelperSettings.Instance.UseRubyFlask = cb_EnableRuby.Checked;
        }

        private void CbEnableDiamondCheckedChanged(object sender, EventArgs e)
        {
            FlaskHelperSettings.Instance.UseDiamondFlask = cb_EnableDiamond.Checked;
        }

        private void CbEnableBleedingCheckedChanged(object sender, EventArgs e)
        {
            FlaskHelperSettings.Instance.UseBleedingFlask = cb_EnableBleeding.Checked;
        }

        private void CbEnableShockCheckedChanged(object sender, EventArgs e)
        {
            FlaskHelperSettings.Instance.UseShockFlask = cb_EnableShock.Checked;
        }

        private void CbEnableBurningCheckedChanged(object sender, EventArgs e)
        {
            FlaskHelperSettings.Instance.UseBurningFlask = cb_EnableBurning.Checked;
        }

        private void CbEnableFrozenCheckedChanged(object sender, EventArgs e)
        {
            FlaskHelperSettings.Instance.UseFrozenFlask = cb_EnableFrozen.Checked;
        }

        private void CbEnableDivinationCheckedChanged(object sender, EventArgs e)
        {
            FlaskHelperSettings.Instance.UseDivinationFlask = cb_EnableDivination.Checked;
        }

        private void CbUseEnergypercentThresholdsCheckedChanged(object sender, EventArgs e)
        {
            FlaskHelperSettings.Instance.UseEnergyShieldThresholds = cb_UseEnergypercentThresholds.Checked;
        }

        #endregion
    }
}
